package somepackage;

import org.fest.assertions.Assertions;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.LoadableComponent;
import org.openqa.selenium.support.ui.WebDriverWait;

public class PageBPage extends LoadableComponent<PageBPage> {
	private final WebDriver driver;

	@FindBy(tagName = "h2")
	private WebElement heading;

	public PageBPage(WebDriver driver) {
		super();
		this.driver = driver;
		PageFactory.initElements(driver, this);
	}

	@Override
	protected void isLoaded() throws Error {
		(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver d) {
                return d.getTitle().equals("Page B");
            }
        });
	}

	@Override
	protected void load() {
		driver.get("http://localhost:8080/foo/page-b.jsf");
	}

	public String getHeading() {
		return heading.getText();
	}

	
}
